# Python 2.6.4
# Project Euler, Problem 43
# Copyright 2010 Talha Zaman

def sub(x,y): return [c for c in x if c not in y]
x = "0123456789"
match = []
for a in x:
    for b in sub(x,a):
        for c in sub(x,a+b):
            for d in sub(x,a+b+c):
                if (int(b+c+d)%2!=0): continue
                for e in sub(x,a+b+c+d):
                    if (int(c+d+e)%3!=0): continue
                    for f in sub(x,a+b+c+d+e):
                        if (int(d+e+f)%5!=0): continue
                        for g in sub(x,a+b+c+d+e+f):
                            if (int(e+f+g)%7!=0): continue
                            for h in sub(x,a+b+c+d+e+f+g):
                                if (int(f+g+h)%11!=0): continue
                                for i in sub(x,a+b+c+d+e+f+g+h):
                                    if (int(g+h+i)%13!=0): continue
                                    for j in sub(x,a+b+c+d+e+f+g+h+i):
                                        if (int(h+i+j)%17!=0): continue
                                        match.append(int(a+b+c+d+e+f+g+h+i+j))
print sum(match)
